<script setup lang="ts">
// 分析: 根据url地址上的订单id 和 支付状态进行展示
import { ApiRes } from '@/types/data'
import { OrderResponse } from '@/types/order'
import request from '@/utils/request'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'

const order = ref<OrderResponse>( {} as OrderResponse)
const route = useRoute()  // payResult=true&orderId=1547484948751028225
// 1. 获取地址栏上的订单id
const orderId = route.query.orderId
// 2. 获取地址栏上的支付结果
const payResult = route.query.payResult
// 3. 判断支付是否成功
const isPayResult = payResult === 'true'
// 4. 根据订单id, 获取订单详情
onMounted(async () => {
  const res = await request.get<ApiRes<OrderResponse>>(`/member/order/${orderId}`)
  console.log(res.data.result);
  order.value = res.data.result
})

</script>

<template>
  <div class="xtx-pay-page">
    <div class="container">
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem to="/cart">购物车</XtxBreadItem>
        <XtxBreadItem>支付结果</XtxBreadItem>
      </XtxBread>
      <!-- 支付结果 -->
      <div class="pay-result">
        <span v-if="isPayResult" class="iconfont icon-queren2 green"></span>
        <span v-else class="iconfont icon-shanchu red" ></span>
        <p class="tit">{{ isPayResult ? '订单支付成功' : '订单支付失败' }}</p>
        <p class="tip">我们将尽快为您发货，收货期间请保持手机畅通</p>
        <p>支付方式：<span>微信支付</span></p>
        <p>支付金额：<span class="pay-money">¥{{ order.payMoney?.toFixed(2) }}</span></p>
        <div class="btn">
          <XtxButton type="primary" style="margin-right:20px">查看订单</XtxButton>
          <XtxButton type="gray">进入首页</XtxButton>
        </div>
        <p class="alert">
          <span class="iconfont icon-tip"></span>
          温馨提示：小兔鲜儿不会以订单异常、系统升级为由要求您点击任何网址链接进行退款操作，保护资产、谨慎操作。
        </p>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.pay-result {
  padding: 100px 0;
  background: #fff;
  text-align: center;
  > .iconfont {
    font-size: 100px;
  }
  .green {
    color: #1dc779;
  }
  .red {
    color: @priceColor;
  }
  .tit {
    font-size: 24px;
  }
  .tip {
    color: #999;
  }
 .pay-money {
    color: #f40; 
    font-weight: bold;
  }
  p {
    line-height: 40px;
    font-size: 16px;
  }
  .btn {
    margin-top: 50px;
  }
  .alert {
    font-size: 12px;
    color: #999;
    margin-top: 50px;
  }
}
</style>